from django.shortcuts import render
# Create your views here.
from rest_framework import mixins
from rest_framework import status
from rest_framework.generics import GenericAPIView
from rest_framework.viewsets import ReadOnlyModelViewSet
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
# from rest_framework_extensions.cache.mixins import CacheResponseMixin

from rest_framework_extensions.cache.mixins import CacheResponseMixin
from .import serializers
from .models import  Area
from rest_framework.viewsets import GenericViewSet





class AreaInfoView(CacheResponseMixin,ReadOnlyModelViewSet):
    # serializer_class = serializers.AreaInfoSerializer
    # queryset = Area.objects.filter(parent__isnull=True)
    def get_serializer_class(self):
        if self.action == "list":
            return serializers.AreaInfoSerializer
        else:
            return serializers.AreaSubsInfoSerializer
    def get_queryset(self):
        if self.action == "list":
            return  Area.objects.filter(parent=None)
        else:
            return  Area.objects.all()

